const {BrowserWindow, globalShortcut} = require('electron')
require('../common/utils/load-env')

//  注册通用快捷键
function registerCommonShortcut(window) {
    window.on('focus', () => {
        globalShortcut.register('ctrl+f12', () => {
            window.webContents.openDevTools()
        })
    })
}

//  创建主窗口
function createMainWindow() {
    const win = new BrowserWindow({
        width: 1200,
        height: 800,
        title: process.env.VITE_APP_NAME,
        //  关闭菜单栏
        autoHideMenuBar: true,
        webPreferences: {
            //  配置渲染进程权限
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    })
    //  加载页面
    let url = process.env.VITE_PROJECT_BASE_URL + '/src/render/window-pages/main-page/main-page-index.html'
    win.loadURL(url)
    //  配置快捷键
    registerCommonShortcut(win)

    return win
}


module.exports = {
    createMainWindow
}